//
//  MainViewController.swift
//  weibo_yaoye
//
//  Created by mac on 15/5/11.
//  Copyright (c) 2015年 mac. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
     //*********  step (8 自定义tabar连线 注册事件)
    @IBOutlet weak var mainTabBar: MainTabBat!

    override func viewDidLoad() {
         //*********  step (3 调用step 2 ， MainTabBar)
        addChildViewController()
        
         //*********  step (9注册事件)
        mainTabBar.composedButton.addTarget(self, action: "clickCompose", forControlEvents: UIControlEvents.TouchUpInside)
    }
     //*********  step (10 实现注册事件 BaseTableViewController)
    func clickCompose()
    {
        
    }
     //*********  step (2 添加控制器到tabbar)
    func  addChildViewController()
    {
        //设置tabbar的文字颜色
        tabBar.tintColor = UIColor.orangeColor()
        //添加控制器
        addChildViewController("Home","首页","tabbar_home")
        addChildViewController("Message","消息","tabbar_message_center")
        addChildViewController("Discover","发现","tabbar_discover")
        addChildViewController("Profile","偶","tabbar_profile")
    
    }
    
     //*********  step (1 写一个通过故事版添加控制器的方法)
    
    func addChildViewController(sbName: String, _ title: String, _ imageName: String)
    {
        let sb = UIStoryboard(name: sbName, bundle: nil)
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        //--------------step <  32 优化 下面这句没有必要  >--------nextsteplocation<<#currentfile#>>---
//        nav.title = title
        //跟控制器的名字
        nav.topViewController.title = title
        nav.tabBarItem.image = UIImage(named: imageName)
        nav.tabBarItem.selectedImage = UIImage(named: imageName + "_highlight")
        addChildViewController(nav)
    }




}




